package stack;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Map;

public class 用栈实现队列_232{

            private Deque<Integer> pushStack = new LinkedList<>();
            private Deque<Integer> popStack = new LinkedList<>();

            /** Initialize your data structure here. */
            public 用栈实现队列_232() {

            }
            
            /** Push element x to the back of queue. */
            public void push(int x) {
                pushStack.push(x);
            }
            
            /** Removes the element from in front of queue and returns that element. */
            public int pop() {
                if(popStack.isEmpty() && !pushStack.isEmpty()) {
                    while(!pushStack.isEmpty()) {
                        popStack.push(pushStack.pop());
                    }
                }
                return popStack.pop();
            }
            
            /** Get the front element. */
            public int peek() {
                if(popStack.isEmpty() && !pushStack.isEmpty()) {
                    while(!pushStack.isEmpty()) {
                        popStack.push(pushStack.pop());
                    }
                }
                return popStack.peek();
            }
            /** Returns whether the queue is empty. */
            public boolean empty() {
                return popStack.isEmpty() && pushStack.isEmpty();
            }
        }

/**
  * Your MyQueue object will be instantiated and called as such:
  * MyQueue obj = new MyQueue();
  * obj.push(x);
  * int param_2 = obj.pop();
  * int param_3 = obj.peek();
  * boolean param_4 = obj.empty();
  */